home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / music / ptreplay.lha / PTReplay / examples / control.c < prev    next >
C/C++ Source or Header  |  1994-12-30  |  7KB  |  280 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : BetaSoft
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30. #include <pragmas/diskfont_pragmas.h>
  31.  
  32. #include "Control.h"
  33.  
  34. struct Screen         *Scr = NULL;
  35. UBYTE                 *PubScreenName = NULL;
  36. APTR                   VisualInfo = NULL;
  37. struct Window         *ControlWnd = NULL;
  38. struct Gadget         *ControlGList = NULL;
  39. struct IntuiMessage    ControlMsg;
  40. struct Gadget         *ControlGadgets[10];
  41. UWORD                  ControlLeft = 150;
  42. UWORD                  ControlTop = 41;
  43. UWORD                  ControlWidth = 298;
  44. UWORD                  ControlHeight = 91;
  45. UBYTE                 *ControlWdt = (UBYTE *)"Player Control";
  46. struct TextAttr       *Font, Attr;
  47. UWORD                  FontX, FontY;
  48. UWORD                  OffX, OffY;
  49. struct TextFont       *ControlFont = NULL;
  50.  
  51. UWORD ControlGTypes[] = {
  52.     TEXT_KIND,
  53.     BUTTON_KIND,
  54.     BUTTON_KIND,
  55.     BUTTON_KIND,
  56.     BUTTON_KIND,
  57.     BUTTON_KIND,
  58.     BUTTON_KIND,
  59.     NUMBER_KIND,
  60.     NUMBER_KIND,
  61.     CHECKBOX_KIND
  62. };
  63.  
  64. struct NewGadget ControlNGad[] = {
  65.     4, 13, 289, 13, (UBYTE *)"Module", NULL, GD_Module, PLACETEXT_ABOVE, NULL, NULL,
  66.     12, 49, 81, 17, (UBYTE *)"_Play", NULL, GD_Play, PLACETEXT_IN, NULL, (APTR)PlayClicked,
  67.     204, 49, 81, 17, (UBYTE *)"_Stop", NULL, GD_Stop, PLACETEXT_IN, NULL, (APTR)StopClicked,
  68.     108, 69, 81, 17, (UBYTE *)"_Quit", NULL, GD_Quit, PLACETEXT_IN, NULL, (APTR)QuitClicked,
  69.     108, 49, 81, 17, (UBYTE *)"P_ause", NULL, GD_Pause, PLACETEXT_IN, NULL, (APTR)PauseClicked,
  70.     12, 69, 81, 17, (UBYTE *)"_Load", NULL, GD_Load, PLACETEXT_IN, NULL, (APTR)LoadClicked,
  71.     204, 69, 81, 17, (UBYTE *)"_Fade", NULL, GD_Fade, PLACETEXT_IN, NULL, (APTR)FadeClicked,
  72.     60, 29, 33, 13, (UBYTE *)"Length", NULL, GD_Length, PLACETEXT_LEFT, NULL, NULL,
  73.     152, 29, 33, 13, (UBYTE *)"Pos", NULL, GD_Pos, PLACETEXT_LEFT, NULL, NULL,
  74.     267, 30, 26, 11, (UBYTE *)"Loop", NULL, GD_Loop, PLACETEXT_LEFT, NULL, (APTR)LoopClicked
  75. };
  76.  
  77. ULONG ControlGTags[] = {
  78.     (GTTX_Text), (ULONG)"None", (GTTX_Border), TRUE, (TAG_DONE),
  79.     (GT_Underscore), '_', (TAG_DONE),
  80.     (GT_Underscore), '_', (TAG_DONE),
  81.     (GT_Underscore), '_', (TAG_DONE),
  82.     (GT_Underscore), '_', (TAG_DONE),
  83.     (GT_Underscore), '_', (TAG_DONE),
  84.     (GT_Underscore), '_', (TAG_DONE),
  85.     (GTNM_Border), TRUE, (TAG_DONE),
  86.     (GTNM_Border), TRUE, (TAG_DONE),
  87.     (GTCB_Checked), TRUE, (GT_Underscore), '_', (TAG_DONE)
  88. };
  89.  
  90. static UWORD ComputeX( UWORD value )
  91. {
  92.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  93. }
  94.  
  95. static UWORD ComputeY( UWORD value )
  96. {
  97.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  98. }
  99.  
  100. static void ComputeFont( UWORD width, UWORD height )
  101. {
  102.     Forbid();
  103.     Font = &Attr;
  104.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  105.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  106.     FontX = GfxBase->DefaultFont->tf_XSize;
  107.     Permit();
  108.  
  109.     OffX = Scr->WBorLeft;
  110.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  111.  
  112.     if ( width && height ) {
  113.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  114.             goto UseTopaz;
  115.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  116.             goto UseTopaz;
  117.     }
  118.     return;
  119.  
  120. UseTopaz:
  121.     Font->ta_Name = (STRPTR)"topaz.font";
  122.     FontX = FontY = Font->ta_YSize = 8;
  123. }
  124.  
  125. int SetupScreen( void )
  126. {
  127.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  128.         return( 1L );
  129.  
  130.     ComputeFont( 0, 0 );
  131.  
  132.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  133.         return( 2L );
  134.  
  135.     return( 0L );
  136. }
  137.  
  138. void CloseDownScreen( void )
  139. {
  140.     if ( VisualInfo ) {
  141.         FreeVisualInfo( VisualInfo );
  142.         VisualInfo = NULL;
  143.     }
  144.  
  145.     if ( Scr        ) {
  146.         UnlockPubScreen( NULL, Scr );
  147.         Scr = NULL;
  148.     }
  149. }
  150.  
  151. void ControlRender( void )
  152. {
  153.     ComputeFont( ControlWidth, ControlHeight );
  154.  
  155.     DrawBevelBox( ControlWnd->RPort, OffX + ComputeX( 4 ),
  156.                     OffY + ComputeY( 45 ),
  157.                     ComputeX( 289 ),
  158.                     ComputeY( 44 ),
  159.                     GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  160. }
  161.  
  162. int HandleControlIDCMP( void )
  163. {
  164.     struct IntuiMessage    *m;
  165.     int            (*func)();
  166.     BOOL            running = TRUE;
  167.  
  168.     while( m = GT_GetIMsg( ControlWnd->UserPort )) {
  169.  
  170.         CopyMem(( char * )m, ( char * )&ControlMsg, (long)sizeof( struct IntuiMessage ));
  171.  
  172.         GT_ReplyIMsg( m );
  173.  
  174.         switch ( ControlMsg.Class ) {
  175.  
  176.             case    IDCMP_REFRESHWINDOW:
  177.                 GT_BeginRefresh( ControlWnd );
  178.                 ControlRender();
  179.                 GT_EndRefresh( ControlWnd, TRUE );
  180.                 break;
  181.  
  182.             case    IDCMP_CLOSEWINDOW:
  183.                 running = ControlCloseWindow();
  184.                 break;
  185.  
  186.             case    IDCMP_VANILLAKEY:
  187.                 running = ControlVanillaKey();
  188.                 break;
  189.  
  190.             case    IDCMP_GADGETUP:
  191.             case    IDCMP_GADGETDOWN:
  192.                 func = ( void * )(( struct Gadget * )ControlMsg.IAddress )->UserData;
  193.                 running = func();
  194.                 break;
  195.         }
  196.     }
  197.     return( running );
  198. }
  199.  
  200. int OpenControlWindow( void )
  201. {
  202.     struct NewGadget    ng;
  203.     struct Gadget    *g;
  204.     UWORD        lc, tc;
  205.     UWORD        wleft = ControlLeft, wtop = ControlTop, ww, wh;
  206.  
  207.     ComputeFont( ControlWidth, ControlHeight );
  208.  
  209.     ww = ComputeX( ControlWidth );
  210.     wh = ComputeY( ControlHeight );
  211.  
  212.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  213.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  214.  
  215.     if ( ! ( ControlFont = OpenDiskFont( Font )))
  216.         return( 5L );
  217.  
  218.     if ( ! ( g = CreateContext( &ControlGList )))
  219.         return( 1L );
  220.  
  221.     for( lc = 0, tc = 0; lc < Control_CNT; lc++ ) {
  222.  
  223.         CopyMem((char * )&ControlNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  224.  
  225.         ng.ng_VisualInfo = VisualInfo;
  226.         ng.ng_TextAttr   = Font;
  227.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  228.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  229.         ng.ng_Width      = ComputeX( ng.ng_Width );
  230.         ng.ng_Height     = ComputeY( ng.ng_Height);
  231.  
  232.         ControlGadgets[ lc ] = g = CreateGadgetA((ULONG)ControlGTypes[ lc ], g, &ng, ( struct TagItem * )&ControlGTags[ tc ] );
  233.  
  234.         while( ControlGTags[ tc ] ) tc += 2;
  235.         tc++;
  236.  
  237.         if ( NOT g )
  238.             return( 2L );
  239.     }
  240.  
  241.     if ( ! ( ControlWnd = OpenWindowTags( NULL,
  242.                 WA_Left,    wleft,
  243.                 WA_Top,        wtop,
  244.                 WA_Width,    ww + OffX + Scr->WBorRight,
  245.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  246.                 WA_IDCMP,    TEXTIDCMP|BUTTONIDCMP|NUMBERIDCMP|CHECKBOXIDCMP|IDCMP_GADGETDOWN|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  247.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  248.                 WA_Gadgets,    ControlGList,
  249.                 WA_Title,    ControlWdt,
  250.                 WA_ScreenTitle,    "PT-Player 2.0  © 1994 BetaSoft",
  251.                 WA_PubScreen,    Scr,
  252.                 TAG_DONE )))
  253.     return( 4L );
  254.  
  255.     GT_RefreshWindow( ControlWnd, NULL );
  256.  
  257.     ControlRender();
  258.  
  259.     return( 0L );
  260. }
  261.  
  262. void CloseControlWindow( void )
  263. {
  264.     if ( ControlWnd        ) {
  265.         CloseWindow( ControlWnd );
  266.         ControlWnd = NULL;
  267.     }
  268.  
  269.     if ( ControlGList      ) {
  270.         FreeGadgets( ControlGList );
  271.         ControlGList = NULL;
  272.     }
  273.  
  274.     if ( ControlFont ) {
  275.         CloseFont( ControlFont );
  276.         ControlFont = NULL;
  277.     }
  278. }
  279.  
  280.